﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OpenCompiler.Scanning.Tests.Specs_for_scanner
{
	[TestClass]
	public class When_scanning_for_formatting
	{
		[TestMethod]
		public void Brackets_are_tokenized()
		{
			const string sourceCode = "{}";
			var tokens = TokenTestHelper.TokenizeWithoutEOF(sourceCode);
			Assert.AreEqual(2, tokens.Count);
			Assert.AreEqual(Formatting.ScopeStart, (Formatting)tokens[0].ActualToken);
			Assert.AreEqual(Formatting.ScopeEnd, (Formatting)tokens[1].ActualToken);
		}

		[TestMethod]
		public void New_lines_are_tokenized()
		{
			const string sourceCode = "{0}{0}";
			NewlineTestRunner.RunAllDefinitions(sourceCode,
			                                    (s) =>
			                                    	{
			                                    		var tokens = TokenTestHelper.TokenizeWithoutEOF(s);
			                                    		Assert.AreEqual(2, tokens.Count);
			                                    		Assert.AreEqual(Formatting.Newline, (Formatting)tokens[0].ActualToken);
			                                    		Assert.AreEqual(Formatting.Newline, (Formatting)tokens[1].ActualToken);
			                                    	});
		}
		
		[TestMethod]
		public void New_lines_seperated_by_brackets_are_tokenized()
		{
			const string sourceCode = "{0}{{{0}}}{0}";
			NewlineTestRunner.RunAllDefinitions(sourceCode,
			                                    (s) =>
			                                    	{
			                                    		var tokens = TokenTestHelper.TokenizeWithoutEOF(s);
			                                    		Assert.AreEqual(5, tokens.Count);
			                                    		Assert.AreEqual(Formatting.Newline, (Formatting)tokens[0].ActualToken);
			                                    		Assert.AreEqual(Formatting.Newline, (Formatting)tokens[2].ActualToken);
			                                    		Assert.AreEqual(Formatting.Newline, (Formatting)tokens[4].ActualToken);
			                                    	});
		}
	}
}